﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using umbraco.MacroEngines;
using umbraco.MacroEngines.Library;

namespace uComponents.RazorModels.Slider
{
	[RazorDataTypeModel("B5BD6E2C-464B-406B-BCCE-A132E7D76981")]
	public class SliderModelBinder : IRazorDataTypeModel
	{
		public int Value1 { get; set; }

		public int Value2 { get; set; }

		public bool Init(int CurrentNodeId, string PropertyData, out object instance)
		{
			if (!string.IsNullOrEmpty(PropertyData))
			{
				int value1, value2;
				var values = PropertyData.Split(',').Select(s => s.Trim()).ToList();

				if (values.Count > 0 && int.TryParse(values[0], out value1))
				{
					this.Value1 = value1;

					if (values.Count > 1 && int.TryParse(values[1], out value2))
					{
						this.Value2 = value2;
					}
				}
			}

			instance = this;

			return true;
		}
	}
}
